<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>hello word</title>
    <style>
        div{
            margin-top: 300px;
            position: relative;
            
        }
        h1{
           
            text-align: center;
            /* text-align: center; */
            
        }
        .but{
            /* margin-left: auto; */
            margin-top: 20px;
           
            position: absolute;
            left:50%;
            transform: translateX(-50%);
        }
        button{
            height: 50px;
            width:100px ;
            margin-left: 30px;
            border-radius: 5px;
        }
    </style>
</head>
<body>
   <div>
    <h1 class="app">Hello word</h1>
   <div class="but">
    <button>文字变红</button>
    <button>文字复原</button>
   </div>
   </div>
</body>
    <script>
        let button = document.getElementsByTagName('button')
        let h = document.querySelector('h1')
        button[0].addEventListener('click',()=>{
            h.style.color='red'
        })
        button[1].addEventListener('click',()=>{
           h.style.color=''
        })
    </script>
</html>